package com.atguigu.behavior.memento;

public class Originator {

    private CareTaker careTaker=new CareTaker();

    private Memento memento;

    public Originator(Memento memento) {
        this.memento = memento;
    }

    public void save(){
        Memento newMemento = new Memento(this.memento.getHp(), this.memento.getState(), this.memento.getItem());
        this.careTaker.addMemento(newMemento);
    }

    public void load(){
        Memento oldMemento = this.careTaker.getMementoList().get(0);
        memento.setHp(oldMemento.getHp());
        memento.setState(oldMemento.getState());
        memento.setItem(oldMemento.getItem());
    }

}
